package entities;

import java.util.ArrayList;
import java.util.ResourceBundle;
import java.util.Vector;

import util.DateFormatting;

/**
 * Entity Class vor Events. An Event has a date, a place and participants.
 * 
 * @author MK
 * 
 */
public class Event {

	protected Long date;
	protected Address place;
	protected ArrayList<Participant> participants;

	public Event() {
		super();
	}

	public Event(Long date, Address place, ArrayList<Participant> participants) {
		super();

		this.date = date;
		this.place = place;

		if (participants == null) {
			this.participants = new ArrayList<Participant>();
		} else {
			this.participants = participants;
		}
	}

	public Event(Event event) {
		this(event.date, event.place, event.participants);
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((date == null) ? 0 : date.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Event other = (Event) obj;
		if (date == null) {
			if (other.date != null)
				return false;
		} else if (!date.equals(other.date))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "Appointment [date=" + date + ", place=" + place + "]";
	}

	public int compareTo(Event event) {

		if (this.date.compareTo(event.date) == 0
				&& this.place.compareTo(event.place) == 0) {
			return 0;
		} else {
			if (this.date.compareTo(event.date) != 0) {
				return this.date.compareTo(event.date);
			} else {
				return this.place.compareTo(event.place);
			}
		}
	}

	public Long getDate() {
		return date;
	}

	public Address getPlace() {
		return place;
	}

	public ArrayList<Participant> getParticipants() {
		return participants;
	}

	public Vector<String> asVector() {

		Vector<String> vector = new Vector<String>();

		vector.add(DateFormatting.toFormattedStringDateAndTime(this.date));
		vector.add(this.getClass().getSimpleName());
		vector.add(this.place.toString());

		return vector;
	}

	public static Vector<String> attributeNames() {

		ResourceBundle messages = ResourceBundle
				.getBundle("bundles.MessagesBundle");

		Vector<String> vector = new Vector<String>();

		vector.add(messages.getString("date"));
		vector.add(messages.getString("type"));
		vector.add(messages.getString("place"));

		return vector;
	}

	public void setParticipants(ArrayList<Participant> participants) {
		this.participants = participants;
	}

	public void setDate(Long date) {
		this.date = date;
	}

	public void setPlace(Address place) {
		this.place = place;
	}
}